﻿using Windows.ApplicationModel.DataTransfer;

namespace Sumc.Client.ModernUI.Helpers
{
    public class ShareService : IShareService
    {
        private readonly DataTransferManager manager;

        public ShareService()
        {
            this.manager = DataTransferManager.GetForCurrentView();
        }

        public string Title { get; set; }

        public string Description { get; set; }

        public string Data { get; set; }

        public void Initialize()
        {
            this.manager.DataRequested += DataRequested;
        }

        public void Remove()
        {
            this.manager.DataRequested -= DataRequested;
        }

        private void DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
        {
            if (this.Title != null)
            {
                args.Request.Data.Properties.Title = this.Title;
            }

            if (this.Description != null)
            {
                args.Request.Data.Properties.Description = this.Description;
            }

            if (this.Data != null)
            {
                args.Request.Data.SetText(this.Data);
            }
        }
    }
}
